/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game;

import game.interfaces.EnglishScrabbleScorerInterface;

/**
 *@author Gary Doyle
 * 
 *Gives a score for a given word based off scoring rules found in game outline.
 */


public class EnglishScrabbleScorer implements EnglishScrabbleScorerInterface {
    
    @Override
    public int StringScore(String word) {

        int[] scoreArr = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10};
        int a = 'a';
        int score = 0;

        
        for (int i = 0; i < word.length(); i++) {
            try{
              String wordLower = word.toLowerCase(); // make sure no uppercase characters entered
            int c = wordLower.charAt(i);
            if (c - a > 25 || c - a < 0) throw new IllegalArgumentException("Non-English Char entered"); // make sure no non-English chars entereed
            
            int temp = (scoreArr[c - a]); // assign a score from the array
            score = score + temp;
        }  
            catch (IllegalArgumentException e){
                //System.out.println("You entered a non-English char");
            }
            }
            
        return score;
    }
}